﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using Common.Logging;
using OutDbContext;
using System.Web.Http.Controllers;
using User.Api.Dto.Hosp;

namespace User.Api.Controllers
{
    public class HospController : ApiController
    {
        private static readonly ILog Logger = LogManager.GetLogger(typeof(HospController));
        private HzfyWeiXinEntities _ctx;

        protected override void Initialize(HttpControllerContext controllerContext)
        {
            _ctx = new HzfyWeiXinEntities();
            base.Initialize(controllerContext);
        }

        protected override void Dispose(bool disposing)
        {
            _ctx.Dispose();
            base.Dispose(disposing);
        }
        /// <summary>
        /// 获取所有公告
        /// </summary>
        /// <param name="orderType">0-预约 2-当天</param>
        /// <returns></returns>
        [HttpGet]
        [ActionName("HospAnnoucementTitle")]
        public HospAnnoucementTitleViewModel HospAnnoucementTitle()
        {
            var news = _ctx.Annoucement.Where(x => x.Status == 0).OrderByDescending(x => x.AddDate).ToList();
            return new HospAnnoucementTitleViewModel
            {
                AnnoucementList = news.Select(x => new HospAnnoucementTitleViewModel.HospAnnoucementViewModel
                {
                    Id = x.Id.ToString(),
                    Title = x.Title,
                    Date = x.AddDate.ToString("yyyy-MM-dd"),
                    ImageUrl = "111"
                }).ToList()
            };
        }

        /// <summary>
        /// 获取公告内容
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [ActionName("HospAnnoucementDetail")]
        public HospAnnoucementDetailViewModel HospAnnoucementDetail(int id)
        {
            //int Id = Convert.ToInt32(id);
            var New = _ctx.Annoucement.FirstOrDefault(x => x.Id == id);
            return new HospAnnoucementDetailViewModel
            {
                Content = New.Content,
                Title=New.Title
            };
        }

        /// <summary>
        /// 获取惠民政策列表
        /// </summary>
        /// <param name="orderType">0-预约 2-当天</param>
        /// <returns></returns>
        [HttpGet]
        [ActionName("PolicyList")]
        public PolicyListViewModel PolicyList()
        {
            var news = _ctx.HuiMinPolicy.Where(x => x.Status == 0).ToList();
            return new PolicyListViewModel
            {
                PolicyLists = news.Select(x => new PolicyListViewModel.PolicyViewModel
                {
                    Id = x.Id.ToString(),
                    Title = x.Title,
                    Date = x.AddDate.ToString("yyyy-MM-dd"),
                }).ToList()
            };
        }

        /// <summary>
        /// 获取惠民政策详情
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [ActionName("PolicyDetail")]
        public PolicyDetailViewModel PolicyDetail(int id)
        {
            //int Id = Convert.ToInt32(id);
            var New = _ctx.HuiMinPolicy.FirstOrDefault(x => x.Id == id);
            return new PolicyDetailViewModel
            {
                Content = New.Content,
                Title = New.Title
            };
        }
    }
}